import java.util.Arrays;

public class quicksort {
    public static void quicksort(int[] arr,int p,int d){//p为扫描指针,d为终止指针
        if(p<d){
            int q=seachersort(arr,p,d);
            quicksort(arr,p,q-1);
            quicksort(arr,q+1,d);
        }

    }
    public static int seachersort(int[] arr,int p,int d){//划分
        int m=p;
        int pivot=arr[p];
        while(p<=d){
            if(pivot>=arr[p]){
              p++;
            }
            else if(pivot<arr[p]){
                int index=arr[d];
                arr[d]=arr[p];
                arr[p]=index;
                d--;
            }
        }
        int indec=arr[d];
        arr[d]=pivot;
        arr[m]=indec;
        return d;
    }
    public static void main(String args[]){
        int[] arr={2,34,5,7,56,99,71,11,32};
        quicksort(arr,0, arr.length-1);
        System.out.println(Arrays.toString(arr));
    }
}
